/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.tbp.gui.table;

import br.com.tbp.model.domain.Consultor;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Diego
 */
public class ConsultoresTableModel extends AbstractTableModel {

    private List<Consultor> lista;

    public ConsultoresTableModel(List<Consultor> lista) {
        this.lista = lista;
    }

    public ConsultoresTableModel() {
        this.lista = new ArrayList<Consultor>();
    }

    public int getRowCount() {
        return lista.size();
    }

    public int getColumnCount() {
        return 4;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return Long.class;
            case 1:
            case 2:
                return String.class;
            case 3:
                return Boolean.class;
        }
        return Object.class;
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID consultor";
            case 1:
                return "Nome";
            case 2:
                return "Telefone";
            case 3:
                return "Ativo?";
        }
        return null;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Consultor c = this.getConsultor(rowIndex);
        if (c != null) {
            switch (columnIndex) {
                case 0:
                    return c.getId();
                case 1:
                    return c.getNome();
                case 2:
                    return c.getTelefone1();
                case 3:
                    return c.isAtivo();
            }
        }
        return null;
    }

    public Consultor getConsultor(int row) {
        if (row >= 0) {
            return lista.get(row);
        }
        return null;
    }

    public boolean removeConsultor(Consultor c) {
        if (lista.remove(c)) {
            fireTableDataChanged();
            return true;
        }
        return false;
    }

    public List<Consultor> getListaDeItens() {
        return new ArrayList<Consultor>(lista);
    }
}
